package com.db.stexchem.client;

import java.io.Closeable;
import java.io.IOException;
import java.net.UnknownHostException;

import com.db.stexchem.exceptions.BadRequestException;
import com.db.stexchem.message.Order;

/**
 * @author Anton Kotov
 * 
 */
public interface Client extends Closeable {

  /**
   * @param listener
   * @throws IllegalArgumentException
   *           - if listener is null
   */
  public void setNotificationListener(final NotificationListener listener)
      throws IllegalArgumentException;

  /**
   * @param host
   *          - server host name
   * @param port
   *          - server port number
   * @param login
   *          - client login name
   * @param password
   *          - client password name
   * @throws IOException
   * @throws UnknownHostException
   * @throws IllegalStateException
   *           - if the client is already connected
   * @throws IllegalArgumentException
   *           - if login or password is null
   * @throws BadRequestException
   *           - if client with such name already connected to the stock
   *           exchange server
   */
  public void connect(final String host, final int port, final String login,
      final String password) throws UnknownHostException, IOException,
      IllegalStateException, IllegalArgumentException, BadRequestException;

  /**
   * @param order
   *          - order to place
   * @return - order number
   * @throws IllegalStateException
   *           - if the client is not connected
   * @throws IllegalArgumentException
   *           - if order is null
   * @throws BadRequestException
   *           - if order is bad request
   * @throws IOExcepption
   *           - if an I/O error occurs
   */
  public int placeOrder(final Order order) throws IllegalStateException,
      IllegalArgumentException, IOException, BadRequestException;

}
